using System;
using UnityEngine;

namespace IQIGame.USDK
{
    public class IQIUSDK : IQIUSDKInterface
    {
        public static IQIUSDK Instance
        {
            get
            {
                if (m_instance == null)
                {
                    m_instance = new IQIUSDK();

                }
                return m_instance;
            }
        }
        private static IQIUSDK m_instance;

        private readonly IQIUSDKInterface iqiUSdkImpl;
        private readonly GameObject iqiUsdkMono;

        private IQIUSDK()
        {
            iqiUsdkMono = new GameObject("IQIUSdkMono");
            GameObject.DontDestroyOnLoad(iqiUsdkMono);
#if UNITY_EDITOR
            iqiUSdkImpl = iqiUsdkMono.AddComponent<IQIUSDKImpl_UnityEditor>();
#elif UNITY_IOS
            iqiUSdkImpl = iqiUsdkMono.AddComponent<IQIUSDKImpl_iOS>();
#elif UNITY_ANDROID
			iqiUSdkImpl = iqiUsdkMono.AddComponent<IQIUSDKImpl_Android>();
#elif UNITY_STANDALONE_WIN
            //TODO: iqiUSdkImpl = ?
#endif
        }


        #region listener
        public Action OnInitSuccess;
        public Action<string> OnInitFailed;

        public Action<UserInfo> OnLoginSuccess;
        public Action<string> OnLoginFailed;
        public Action OnLoginCancel;

        public Action<UserInfo> OnSwitchSuccess;
        public Action<string> OnSwitchFailed;
        public Action OnSwitchCancel;

        public Action OnLogoutSuccess;
        public Action<string> OnLogoutFailed;
        public Action OnLogoutCancel;

        public Action<PayResultData> OnPaySuccess;
        public Action<PayResultData> OnPayFailed;
        public Action<PayResultData> OnPayCancel;

        public Action OnExitSuccess;
        public Action<string> OnExitFailed;
        public Action OnExitCancel;

        public Action<ExtraFuncData> OnExtraFuncSuccess;
        public Action<ExtraFuncData> OnExtraFuncFailed;
        #endregion

        #region Req

        public void init()
        {
            iqiUSdkImpl.init();
        }

        public void login()
        {
            iqiUSdkImpl.login();
        }

        public void logout()
        {
            iqiUSdkImpl.logout();
        }

        public void exit()
        {
            iqiUSdkImpl.exit();
        }

        public void switchAccount()
        {
            iqiUSdkImpl.switchAccount();
        }

        public bool isSupportExitDialog()
        {
            return iqiUSdkImpl.isSupportExitDialog();
        }

        public bool isSupportSwitchAccount()
        {
            return iqiUSdkImpl.isSupportSwitchAccount();
        }

        public void pay(PaymentParameters orderInfo, RoleInfo roleInfo)
        {
            iqiUSdkImpl.pay(orderInfo, roleInfo);
        }

        public void extraFunc(ExtraFuncType type, string jsonData)
        {
            iqiUSdkImpl.extraFunc(type, jsonData);
        }

        public void extraFunc(ExtraFuncType type)
        {
            iqiUSdkImpl.extraFunc(type, "{}");
        }

        public void setAgreeProtocol()
        {
            iqiUSdkImpl.setAgreeProtocol();
        }

        public void enterGame(RoleInfo roleInfo)
        {
            iqiUSdkImpl.enterGame(roleInfo);
        }

        public void createNewRole(RoleInfo roleInfo)
        {
            iqiUSdkImpl.createNewRole(roleInfo);
        }

        public void roleLevelUp(RoleInfo roleInfo)
        {
            iqiUSdkImpl.roleLevelUp(roleInfo);
        }

        public void roleSelectServer(RoleInfo roleInfo)
        {
            iqiUSdkImpl.roleSelectServer(roleInfo);
        }

        public void roleExitGame(RoleInfo roleInfo)
        {
            iqiUSdkImpl.roleExitGame(roleInfo);
        }

        public void roleReport(RoleInfo roleInfo)
        {
            iqiUSdkImpl.roleReport(roleInfo);
        }

        #endregion

        #region property

        public int getChannelId()
        {
            return iqiUSdkImpl.getChannelId();
        }

        public string getChannelName()
        {
            return iqiUSdkImpl.getChannelName();
        }

        public int getImgId()
        {
            return iqiUSdkImpl.getImgId();
        }

        public string getCpsId()
        {
            return iqiUSdkImpl.getCpsId();
        }

        public string getChannelSDKVersion()
        {
            return iqiUSdkImpl.getChannelSDKVersion();
        }

        public string getUSDKVersion()
        {
            return iqiUSdkImpl.getUSDKVersion();
        }

        public string getCustomParams(string key)
        {
            return iqiUSdkImpl.getCustomParams(key);
        }

        public string getUniqueId()
        {
            return iqiUSdkImpl.getUniqueId();
        }

        public string getTraceID()
        {
            return iqiUSdkImpl.getTraceID();
        }

        #endregion

    }
}
